<template>
  <div>
  <el-card>
  <el-row style="float: left;">
    <el-button icon="el-icon-search" style="background: #D3DCE6;" @click='chaxun'>查询</el-button>
  </el-row>
  <el-table :data="tableDate" border>
 <el-table-column label="任务名称" prop="rwname" width="160px"></el-table-column>
 <el-table-column label="任务编号" prop="rwid"></el-table-column>
        <el-table-column label="下发人" prop="createby" width="100px"></el-table-column>
        <el-table-column label="巡检线路" prop="xianlu.xlname" width="100px"></el-table-column>
        <el-table-column label="下发时间" prop="createtime"></el-table-column>
        <el-table-column label="完成时间" prop="oktime"></el-table-column>
        <el-table-column label="状态" prop="type" width="100px"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope" width='270px;'>
            <el-button type="text" size="small" @click="chakan(scope.row)" :disabled="rname.indexOf('系统管理员')!=-1">查看</el-button>
            <el-button type="text" size="small" @click="huizhi(scope.row)" :disabled="rname.indexOf('系统管理员')!=-1">回执录入</el-button>
          </template>
        </el-table-column>
  </el-table>
  <el-pagination @current-change="pager" @prev-click="pager" @next-click="pager" background layout="prev,pager,next,total,jumper"
    :total="total" :page-size="
  size"></el-pagination>
  </el-card>
  <el-dialog title="联合搜索" :visible.sync="searchvisible" width="40%" style="text-align: center;margin: auto;">
    <el-form :model="searchForm">
      <el-form-item label="任务编号" label-width="100px">
        <el-input v-model="searchForm.rwid" style="width: 220px;"></el-input>
      </el-form-item>
      <el-form-item label="下发人" label-width="100px">
        <el-input v-model="searchForm.createby" style="width: 220px;"></el-input>
      </el-form-item>
      <el-form-item label="完成时间" label-width="100px">
        <el-date-picker v-model="searchForm.okdate" type="date" value-format="yyyy-MM-dd" style="width: 220px;"></el-date-picker>
      </el-form-item>
      <el-form-item label="状态" label-width="100px">
        <el-select v-model="searchForm.type" style="width: 220px;">
          <el-option v-for="item in type" :value="item.value" :label="item.value" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <template>
        <el-button @click="searchvisible = false">取 消</el-button>
        <el-button type="primary" @click="searchclose()">确 定</el-button>
      </template>
    </el-form>
  </el-dialog>
  </div>
</template>
<script>
  import axios from 'axios'
  export default{
    data(){
      return{
        searchvisible:false,
        searchForm:{
        rwid:'',
        createby:'',
        type:'',
        okdate:''
        },
        type: [{
            value: '已完成'
          },
          {
            value: '待分配'
          },
          {
            value: '已分配'
          },
          {
            value: '已完成'
          }
        ],
        size:3,
        tableDate:[],
        total:0,
        click:'all',
        rname:''
      }
    },
    methods:{
    chaxun:function(){
      this.searchvisible=true
    },
    getData:function(pageNo){
      console.log(this.$store.state.user)
      var name=''
      this.$store.state.user.roles.forEach(item=>{
        name+=item.rname+','
      })
      let postDate=this.$qs.stringify({
        uid:this.$store.state.user.uid,
        pageNo:pageNo,
        pageSize:this.size
      })
      console.log(name)
      if(name.indexOf('系统管理员')!=-1){
      axios.post('http:localhost:8086/zhu/selectAll',postDate).then(vs=>{
        this.tableDate=vs.data.list
        this.total=vs.data.total
        this.tableDate.forEach(item=>{
          item.createtime=this.aaa(item.createtime)
          item.okdate=this.aaa(item.okdate)
        })
      })
      }else{

      axios.post('http:localhost:8086/zhu/selectXunjianByuid',postDate).then(vs=>{
        this.tableDate=vs.data.list
        this.total=vs.data.total
        this.tableDate.forEach(item=>{
          item.createtime=this.aaa(item.createtime)
          item.okdate=this.aaa(item.okdate)
        })
      })
      }
    },
    aaa: function(asd) {
      if(asd==null){
        return
      }
      var date = new Date(asd) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
      var Y = date.getFullYear() + '-'
      var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
      var D = date.getDate() + ' '
      var h = date.getHours() + ':'
      var m = date.getMinutes() + ':'
      var s = date.getSeconds()

      console.log(Y + M + D + h + m + s);
      return Y + M + D + h + m + s;
    },
    searchclose:function(pageNo){
      pageNo=1
    console.log(this.searchForm)
    let postDate=this.$qs.stringify({
      rwid:this.searchForm.rwid,
      createby:this.searchForm.createby,
      okdate:this.searchForm.okdate,
      type:this.searchForm.type,
      uid:this.$store.state.user.uid,
      pageNo:pageNo,
      pageSize:this.size
    })
    axios.post('http:localhost:8086/zhu/whereAnduid',postDate).then(vs=>{
      this.tableDate=vs.data.list
      this.total=vs.data.total
      this.tableDate.forEach(item=>{
        item.createtime=this.aaa(item.createtime)
        item.okdate=this.aaa(item.okdate)
      })
      this.searchvisible=false

    })
    },
    pager:function(pageNO){
    if(this.click=='all'){
     this.getData(pageNo)
    }else if(this.click=='where'){
      this.get
    }
    },
    chakan(row) {
      console.log(row)
      this.$router.push({
        path: '/chakan2',
        query: row
      })
    },
    huizhi:function(row){
    let post=this.$qs.stringify({
      zhuid:row.id,
      uid:this.$store.state.user.uid
    })
    console.log(1)
    axios.post("http:localhost:8086/zi/selectIsHas",post).then(vs=>{
    if(vs.data==false){
    this.$message("这个任务已经提交回执请别重复提交")
    console.log(2)
    return
    }
    console.log(3)
    })
    console.log(4)
    console.log(row)
    let postDate=this.$qs.stringify({
      id:row.id
    })
    axios.post("http:localhost:8086/zhu/updateXunjianTypezhixing",postDate).then(vs=>{
      if(vs.status==200){
      this.$router.push({path:'/huizhi',query:row})
      }
    })
    }
    },
    created() {
    this.getData(1)
    this.$store.state.user.roles.forEach(item=>{
      this.rname+=item.rname+','
    })
    }
  }

</script>
<style></style>
